<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>七海后台管理系统</title>
    <link rel="stylesheet" href="/static/plugins/layui/css/layui.css">
</head>

<body>
    <div class="layui-layout layui-layout-admin">
        <!-- 引入公共页面 -->
        {{include "./common/header.html" }}
        <!-- 引入公共页面 -->
        {{include "./common/side-menu.html" }}


        <div class="layui-body">
            <!-- 内容主体区域 -->
            <div style="padding: 15px;">
                <span class="layui-breadcrumb" lay-separator=">">
                    <a href="/">首页</a>
                    <a href="/addCate">分类添加</a>
                </span>
                <form style="padding: 15px;" class="layui-form" id="theform">
                    <div class="layui-form-item">
                        <label class="layui-form-label">分类名称： </label>
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input" name="cate_name" autocomplete="off">
                        </div>
                    </div>

                    <div class="layui-form-item ">
                        <label class="layui-form-label "> 显示首页： </label>
                        <div class="layui-input-block">
                            <input type="radio" name="is_show" value='1' title="显示" checked="checked">
                            <input type="radio" name="is_show" value='0' title="不显示">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label>内容:</label>
                        <div id="demo">

                        </div>
                    </div>


                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <!-- <button class="layui-btn layui-btn-normal">添加</button> -->
                            <input type="button" id="add" class="layui-btn layui-btn-normal" value="添加">
                        </div>
                    </div>
            </div>
            </form>
        </div>
    </div>


    <!-- 引入公共页面 -->
    {{include "./common/footer.html" }}

    </div>
</body>
<script src="/static/js/jquery.js"></script>
<script src="/static/plugins/layui/layui.js"></script>
<script src="https://cdn.jsdelivr.net/npm/wangeditor@latest/dist/wangEditor.min.js"></script>
<script>
    // 初始化富文本编辑器
    const E = window.wangEditor
    const editor = new E('#demo')
    editor.config.uploadImgShowBase64 = true
    editor.create()

     layui.use(['element', 'layer', 'util'], function () {
            var element = layui.element
                , layer = layui.layer
                , util = layui.util
                , $ = layui.$;

            //头部
            util.event('lay-header-event', {
                //左侧菜单
                menuLeft: function (othis) {
                    layer.msg('展开左侧菜单的操作111', { icon: 0 });
                }
                , menuRight: function () {
                    layer.open({
                        type: 1
                        , content: '<div style="padding: 15px;">处理右侧面板的操作234</div>'
                        , area: ['260px', '100%']
                        , offset: 'rt' 
                        , anim: 5
                        , shadeClose: true
                    });
                }
            });

        });

        // 添加分类
        $("#add").click(function () {
            let formData = new FormData($('#theform')[0])
            // console.log(editor.txt.html());
            $.ajax({
                type: "post",
                url: "/ajaxAddCate",
                data: formData,
                processData: false,
                contentType: false,  
            }).then(({ code,message }) => {
                layer.msg(message)
                if(code === 20000){
                    location.href="/catelist"
                }
            })
        })

</script>
</html>